package smallchange;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class SmallChangeSys {
    public static void main(String[] args) {
        boolean flag = true;
        Scanner scanner = new Scanner(System.in);

        String details = "-------------零钱通明细-------------";
        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        double money = 0;
        double balance = 0;
        String note = "";

        do{
            System.out.println("==============零钱通菜单==============");
            System.out.println("\t\t\t1. 零钱通明细");
            System.out.println("\t\t\t2. 收益入账");
            System.out.println("\t\t\t3. 消    费");
            System.out.println("\t\t\t4. 退    出");
            System.out.print("请选择:>");
            int input = scanner.nextInt();
            switch (input){
                case 1:
                    System.out.println(details);
                    break;
                case 2:
                        System.out.print("收益入账:>");
                        money = scanner.nextDouble();
                        if(money <= 0){
                            System.out.println("请输入正确的金额!");
                            break;
                        }
                            balance += money;
                            date = new Date();
                            details += "\n收益入账\t+" + money + "\t" + sdf.format(date) + "\t余额:" + balance;
                    break;
                case 3:
                    if(balance <= 0 ){
                        System.out.println("穷逼,没钱你消费个蛋!");
                        break;
                    }
                    System.out.print("请输入消费金额:>");
                    money  = scanner.nextInt();
                    if(money <= 0 || money > balance){
                        System.out.println("输入错误，金额应在0-" + balance);
                        break;
                    }
                    System.out.print("请输入消费场所:>");
                    note = scanner.next();
                    balance -= money;
                    date = new Date();
                    details += "\n" + note + "\t-" + money + "\t" + sdf.format(date) + "\t余额:" + balance;

                    break;
                case 4:
                    System.out.println("你确定要退出吗? y/n");
                    while (true){
                        System.out.print("请选择:>");
                        String df = scanner.next();
                        if(df.equals("y")){
                            System.out.println("程序退出!");
                            flag = false;
                            break;
                        }
                        else if(df.equals("n")){
                            System.out.println("退回主菜单!");
                            break;
                        }
                        else {
                            System.out.println("输入错误,请重新选择!");
                        }

                    }
                    break;
                default:
                    System.out.println("选择错误!");
                    break;
            }

                    }while(flag);
    }

}
